package com.jzhao.gper.spring.v3.aop.aspect;

import com.jzhao.gper.spring.v3.aop.intercept.JZJoinPoint;
import com.jzhao.gper.spring.v3.aop.intercept.JZMethodInterceptor;
import com.jzhao.gper.spring.v3.aop.intercept.JZMethodInvocation;

import java.lang.reflect.Method;

/**
 * @author jzhao
 * @date 2020/4/21 9:31
 */
public class JZAfterReturningAdviceInterceptor extends JZAbstractAspectJAdvice implements JZMethodInterceptor {

    private JZJoinPoint jp;

    public JZAfterReturningAdviceInterceptor(Object aspect, Method adviceMethod) {
        super(aspect, adviceMethod);
    }

    public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable {
        invokeAdviceMethod(this.jp, returnValue, null);
    }

    @Override
    public Object invoke(JZMethodInvocation mi) throws Throwable {
        this.jp = mi;
        Object result = mi.proceed();
        afterReturning(result,mi.getMethod(), mi.getArguments(), mi.getThis());
        return result;
    }
}
